package com.ruoyi.web.controller.comment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.comment.domain.SysUserComment;
import com.ruoyi.comment.service.ISysUserCommentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户和评论关联Controller
 *
 * @author zhezhi
 * @date 2022-10-06
 */
@RestController
@RequestMapping("/comment/commentUser")
public class SysUserCommentController extends BaseController
{
    @Autowired
    private ISysUserCommentService sysUserCommentService;

    /**
     * 查询用户和评论关联列表
     */
    @PreAuthorize("@ss.hasPermi('comment:commentUser:list')")
    @GetMapping("/list")
    @ApiOperation("查询用户和评论关联列表")
    public TableDataInfo list(SysUserComment sysUserComment)
    {
        startPage();
        List<SysUserComment> list = sysUserCommentService.selectSysUserCommentList(sysUserComment);
        return getDataTable(list);
    }

    /**
     * 导出用户和评论关联列表
     */
    @PreAuthorize("@ss.hasPermi('comment:commentUser:export')")
    @Log(title = "用户和评论关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出用户和评论关联列表")
    public void export(HttpServletResponse response, SysUserComment sysUserComment)
    {
        List<SysUserComment> list = sysUserCommentService.selectSysUserCommentList(sysUserComment);
        ExcelUtil<SysUserComment> util = new ExcelUtil<SysUserComment>(SysUserComment.class);
        util.exportExcel(response, list, "用户和评论关联数据");
    }

    /**
     * 获取用户和评论关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('comment:commentUser:query')")
    @GetMapping(value = "/{userId}")
    @ApiOperation("获取用户和评论关联详细信息")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(sysUserCommentService.selectSysUserCommentByUserId(userId));
    }

    /**
     * 新增用户和评论关联
     */
    @PreAuthorize("@ss.hasPermi('comment:commentUser:add')")
    @Log(title = "用户和评论关联", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增用户和评论关联")
    public AjaxResult add(@RequestBody SysUserComment sysUserComment)
    {
        return toAjax(sysUserCommentService.insertSysUserComment(sysUserComment));
    }

    /**
     * 修改用户和评论关联
     */
    @PreAuthorize("@ss.hasPermi('comment:commentUser:edit')")
    @Log(title = "用户和评论关联", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改用户和评论关联")
    public AjaxResult edit(@RequestBody SysUserComment sysUserComment)
    {
        return toAjax(sysUserCommentService.updateSysUserComment(sysUserComment));
    }

    /**
     * 删除用户和评论关联
     */
    @PreAuthorize("@ss.hasPermi('comment:commentUser:remove')")
    @Log(title = "用户和评论关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    @ApiOperation("删除用户和评论关联")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(sysUserCommentService.deleteSysUserCommentByUserIds(userIds));
    }
}
